<?php
/*
 * @Author: your name
 * @Date: 2020-07-09 15:28:14
 * @LastEditTime: 2020-07-15 09:32:44
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \tplay\app\api\controller\page.php
 */ 

namespace app\api\controller;
use Firebase\JWT\JWT;
use think\Db;
class Leader extends Index
{
    /***
    * @api {服务器} http://baiying.dobest.site/api/Leader/GetBar
    * 本地 http://www.tpxiang.com/api/Leader/GetBar
    * @apiGroup tplay_product
    * @apiParam {string} title 导航栏
    * @apiParam {string} content 内容
    *
    * @apiSuccessExample success->Response:{
    * "code":200
    * "msg" :"成功"
    * "data":[]
    * }
    * @apiErrorExample error->Response:{
    * "code":0
    * "msg" :"失败"
    * }
    */
     public function GetBar()
    {
        if(request()->isGet()){
            $data=Db::name('bar a')
            ->field('a.id,a.name')
            ->select();
            if(!$data){
                return $this->return_msg(400,'失败');
            }
            return $this->return_msg(200,'成功',$data);
        }
        return $this->return_msg(500,'非法调用');
    }


 /***
    * @api {服务器} http://baiying.dobest.site/api/Leader/HuanList
    * 本地 http://www.tpxiang.com/api/Leader/HuanList
    * @apiGroup tplay_product
    * @apiParam {string} title 幻灯片
    * @apiParam {string} content 内容
    *
    * @apiSuccessExample success->Response:{
    * "code":200
    * "msg" :"成功"
    * "data":[]
    * }
    * @apiErrorExample error->Response:{
    * "code":0
    * "msg" :"失败"
    * }
    */

    public function HuanList()
    {
        if(request()->isGet()){
            $data=Db::name('huan a')
            ->join('attachment b','a.attid=b.id')
            ->field('a.id,a.name,b.filepath')
            ->where('a.typal_id','=','1')
            ->limit(0,10)
            ->select();
            foreach ($data as $key=>&$v){
                $v['filepath']='http://'.$_SERVER['HTTP_HOST'].$v['filepath'];//拼接
            }
            if(!$data){
                return $this->return_msg(400,'失败');
            }
            return $this->return_msg(200,'成功',$data);
        }
        return json(['code'=>0,'msg'=>'非法调用','data'=>[]]);
    
    }




    /***
     * @api {服务器} http://baiying.dobest.site/api/Leader/GetCategories
    * 本地 http://www.tpxiang.com/api/Leader/GetCategories
     * @apiGroup tplay_product
     * @apiParam {string} title 分类/文章
     * @apiParam {string} content 内容
     * @apiSuccessExample success->Response:{
     * "code":200
     * "msg" :"成功"
     * "data":[]
     * }
     * @apiErrorExample error->Response:{
     * "code":0
     * "msg" :"失败"
     * }
     */
    public function GetCategories(){
        $data_type=Db::name('article_cate')
        ->field('id,name,tag')
            ->where(['name'=>['in','服务项目,最新案例,新闻中心']])
            ->order('id')
            ->select();
        $ids = array_column($data_type,'id');
        $data_pro = Db::name('article a')
                ->join('attachment b','a.thumb=b.id')
                ->where(['article_cate_id'=>['in',$ids]])
                ->field('a.id,a.article_cate_id,a.title,a.tag,a.description,b.filepath,a.create_time')
                ->order('id desc')
                ->select();
        $arr_pro = [];
        foreach ($data_pro as &$v){
            $v['filepath'] = 'http://' . $_SERVER['SERVER_NAME'] . $v['filepath'];//拼接图片
            $arr_pro[$v['article_cate_id']][] = $v;
        }
        foreach ($data_type as $key=> &$v){
            $v['article'] = $arr_pro[$v['id']] ? $arr_pro[$v['id']] : '';
        }
        if (!$data_type){
            return json(['code'=>0,'msg'=>"无数据",'data'=>[]]);
        }
        return json(['code'=>200,'msg'=>"成功",'data'=>$data_type]);
    }

    /***
     * @api {post} http://www.tpxiang.com//api/Leader/Parameter
     * @apiGroup tplay_product
     * @apiParam {string} title 分类
     * @apiParam {string} content 内容
     * @apiSuccessExample success->Response:{
     * "code":200
     * "msg" :"成功"
     * "data":[]
     * }
     * @apiErrorExample error->Response:{
     * "code":0
     * "msg" :"失败"
     * }
     */
    public function Parameter(){
         $id = $this->request->has('id') ? $this->request->param('id', 0, 'intval') : 0;//判断有无参数
         if(request()->isGet()){
             $data=Db::name('article a')
                 ->join('attachment b','a.thumb=b.id')
                 ->field('a.id,a.title,a.tag,a.content,b.filepath,a.create_time')
                 ->where('a.status','=','0')//判断状态
                 ->where('a.id',$id)//判断参数
                 ->limit(0,10)
                 ->select();
                 foreach ($data as $key=>&$v){
                     $v['filepath']='http://'.$_SERVER['HTTP_HOST'].$v['filepath'];//拼接
                     $v['content']= strip_tags(htmlspecialchars_decode($v['content']));//去掉富文本标签
                }
                if(!$data){
                    return $this->return_msg(400,'失败');
                }
                return $this->return_msg(200,'成功',$data);
            }
            return $this->return_msg(500,'非法调用');
        }
    
    /***
     * @api {服务器} http://baiying.dobest.site/api/Leader/Site
     * 本地 ：：：http://www.tpxiang.com//api/Leader/Site
     * @apiGroup tplay_product
     * @apiParam {string} title 地址
     * @apiParam {string} content 内容
     * @apiSuccessExample success->Response:{
     * "code":200
     * "msg" :"成功"
     * "data":[]
     * }
     * @apiErrorExample error->Response:{
     * "code":0
     * "msg" :"失败"
     * }
     */
    public function Site(){
        if(request()->isGet()){
            $data=Db::name('site')
                ->field('id,site,serial,phone,email')
                ->where('status','=','1')
                ->limit(0,10)
                ->select();
                if(!$data){
                    return $this->return_msg(400,'失败');
                }
                return $this->return_msg(200,'成功',$data);
            }
            return $this->return_msg(500,'非法调用');
        }

}